//订单状态
function statusValue(value,row,index){
	if (value == -4) {
		return "反审核";
	}else if(value == -3){
		return "被退回";
	}else if(value == -2){
		return "未审核";//或审核中
	}else if(value == -1){
		return "未通过";
	}else if(value == 0){
		return "待提交";
	}else if(value == 1){
		return "已审核";
	}else if(value == 2){
		return "待派单";
	}else if(value == 3){
		return "待抢单";
	}else if(value == 4){
		return "待预约";
	}else if(value == 6){
		return "待签到";
	}else if(value == 7){
		return "待完成";
	}else if(value == 8){
		return "已完成";
	}else if(value == 9){
		return "已取消";
	}else if(value == 10){
		return "已逾期";
	}else if(value == 11){
		return "已作废";
	}else if(value == 12){
		return "已删除";
	}else if(value == 13){
		return "配单失败";
	}else if(value == 14){
		return "接单失败";
	}else if(value == 15){
		return "被放弃";
	}else if(value == 16){
		return "待接单";
	}else if(value == 17){
		return "预约失败";
	}else if(value == 18){
		return "再上门";
	}
}

//刷单状态
function flagValue(value,row,index){
	if(value == 1){
		return "是";
	}else{
		return "否";
	}
}

function needSettlementValue(value,row,index){
	if(value == 1){
		return "不结算";
	}else{
		return "结算";
	}
}
//layer弹出区域在小屏幕下显示不全问题处理
var winH = window.screen.height;
var arrLayerPart = new Array();
if(winH <=900){
	arrLayerPart =['1100px', '500px'];
}else{
	arrLayerPart =['1200px', '850px'];
}

//物流状态
function logisticsValue(value,row,index){
	if(value == 0){
		return "已发货";
	}else if(value == 1){
		return "已签收";
	}else if(value == 2){
		return "在途";
	}else if(value == 3){
		return "拒签";
	}else if(value == 4){
		return "未发货";
	}else{
		return "";
	}
}
//订单来源
function originValue(value,row,index){
	if(value == 0){
		return "商家添加";
	}else if(value == 1){
		return "淘宝/天猫店铺";
	}else if(value == 2){
		return "京东";
	}else if(value == 3){
		return "官方网站";
	}else if(value == 4){
		return "APP";
	}else if(value == 5){
		return "天猫建材安装服务系统";
	}else if(value == 6){
		return "平台添加";
	}else if(value == 7){
		return "淘宝后服务平台";
	}else if(value == 8){
		return "线下渠道订单";
	}else if(value == 9){
		return "线下自营订单";
	}
}

//售后状态
function asStatusValue(value,row,index){
	if(value == 0){
		return "待受理";
	}else if(value == 1){
		return "已经受理";
	}else if(value == 2){
		return "处理完毕";
	}else if(value == 3){
		return "退回";
	}else{
		return "无售后";
	}
}

//OrderType 接单类型
function typeValue(value,row,index){
	if(value == -1){
		return "未派工";
	}else if(value == 0){
		return "指派";
	}else if(value == 1){
		return "抢单";
	}else if(value == 2){
		return "推送接单";
	}else{
		return "";
	}
}

//配单状态
function peidanStatus(value,row,index){
	if(value > 0){
		return "已配单";
	}else{
		return "未配单";
	}
}

//天猫工单核销状态
function tmallWriteOffValue(value,row,index){
	var msg ="";
	if(value == -2){
		msg= "无需核销";
	}else if(value == -1){
		msg=  "核销失败";
	}else if(value == 0){
		msg=  "等待核销";
	}else if(value == 1){
		msg=  "核销完成";
	}else if(value == 2){
		msg=  "部分核销";
	}else if(value == 3){
		msg=  "人工核销";
	}
	var orderId = row.id;
	return '<a href="javascript:tmallWriteOff(\''+orderId+'\');">'+msg+'</a>'; 
}

//商家后台核销状态
function sellertmallWriteOffValue(value,row,index){
	var msg ="";
	if(value == -2){
		msg= "无需核销";
	}else if(value == -1){
		msg=  "核销失败";
	}else if(value == 0){
		msg=  "等待核销";
	}else if(value == 1){
		msg=  "核销完成";
	}else if(value == 2){
		msg=  "部分核销";
	}else if(value == 3){
		msg=  "人工核销";
	}
	return msg;
}

//天猫直营
function tmallDirectlyValue(value,row,index){
	var msg ="";
	if(value == 1){
		msg= "<a href=\"javascript:showTmallAdjInfo('"+row.number+"')\">是("+(row.adjnum==null?'0':('<font color="red">'+row.adjnum+'</font>'))+"调整单)</a>";
	}else{
		msg=  "否";
	}
	//alert(value+"//"+msg);
	return msg;
}
function tmallWriteOff(orderId){
	parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '天猫核销记录',
        content:['buiNeworder/tmallWriteOffMsg.do?orderId='+orderId,'no'],
        area: ['800px', '400px'],
        
	});
}

//服务类型
function formatXMSPType (value,row,index){
	if(value==1){
		return "安装";
	}else if(value==2){
		return "配送";
	}else if(value == 3){
		return "测量";
	}else if(value == 4){
		return "维修";
	}else if(value == 5){
		return "安装+配送";
	}
}

//获取多选的IDS
function getSelections(){
	var ids ="";
	var rows = $('#dg').datagrid('getSelections');
	for(var i=0; i<rows.length; i++){  
        ids+=rows[i].id+",";
    }  
    if(ids.length==0){
		  parent.layer.alert("请选择要操作的服务单！",{icon:7});
		   return 0;
	  }
    return ids;
}
//获取单选id
function selectid(){
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length == 0){
		parent.layer.alert("请选择要操作的服务单！");
    	return 0;
	}
    if(rows.length > 1){
    	parent.layer.alert("只能选择一条服务单！");
    	return 0;
    }
    var row = rows[0];
	if(row.serviceStatus == 0){
		parent.layer.alert("该订单处于暂停状态，无法进行操作！",{icon:7});
		return 0;
	}
    return row.id;
}

//获取单选row的数据
function selectRow(){
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length == 0){
		parent.layer.alert("请选择要操作的服务单！",{icon:7});
		return 0;
	}
	if(rows.length > 1){
		parent.layer.alert("只能选择一条服务单！",{icon:7});
		return 0;
	}
	var row = rows[0];
	if(row.serviceStatus == 0){
		parent.layer.alert("该订单处于暂停状态，无法进行操作！",{icon:7});
		return 0;
	}
	return row;
}

//修改服务单
function editOrder(url){
	var row = selectRow();
	if(row == 0){
		return false;
	}else{
		if(row.origin!= 6 && row.origin!= 8 && row.origin != 1 ){
			parent.layer.alert("非平台手动添加的服务单不可修改！",{icon:7});
			return false;
		}else{
			if(row.status >= 1){
				parent.layer.alert("已审核服务单，不可修改！！",{icon:7});
				return false;
			}else{
				self.location=url+"?id="+row.id;
			}
		}
	}
}

//修改紧急标记
function editMark(markVal,url){
	var ids ="";
	var markCount = 0;//紧急个数
	var nomalCount = 0;//正常个数
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length==0){
		  parent.layer.alert("请选择要操作的服务单！",{icon:7});
		  return false;
	  }
	for(var i=0; i<rows.length; i++){
		if(rows[i].mark == 0){
			nomalCount++;
		}else{
			markCount++;
		}
		//判断订单是否处于暂停状态
		if(rows[i].serviceStatus == 0){
			parent.layer.alert("选择的订单中有处于暂停状态的订单，无法进行操作！",{icon:7});
		    return false;
		}
        ids+=rows[i].id+",";
    }  
	if(markVal == 1 &&nomalCount== 0){
		parent.layer.alert("该服务单已经标记为紧急,请不要重复操作!",{icon:7});
		return false;
	}
	if(markVal == 0 &&markCount== 0){
		parent.layer.alert("该服务单已经标记为正常,请不要重复操作!",{icon:7});
		return false;
	}
	$.ajax({  
         type:'POST',      
	     url:url,  
	     data:{'orderids':ids,'mark':markVal},  
	     cache:false,  
	     dataType:'json',  
	     success:function(data){  
		    if(data.success){
		    	parent.layer.alert(data.result);
		    	search();
				}else{
					parent.layer.alert(data.result);
				}
	     }  
		}); 
}

//修改刷单标记
function editFlag(flagVal,url){
	var ids ="";
	var flagCount = 0;//刷单个数
	var nomalCount = 0;//正常个数
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length==0){
		  parent.layer.alert("请选择要操作的服务单！",{icon:7});
		  return false;
	  }
	for(var i=0; i<rows.length; i++){
		if(rows[i].isSettlement == 1){
			parent.layer.alert("服务单已经结算,不能标记为刷单!",{icon:7});
			return false;
		}
		//判断订单是否处于暂停状态
		if(rows[i].serviceStatus == 0){
			parent.layer.alert("选择的订单中有处于暂停状态的订单，无法进行操作！",{icon:7});
		    return false;
		}
		if(rows[i].flag == 0){
			nomalCount++;
		}else{
			flagCount++;
		}
        ids+=rows[i].id+",";
    }  
	if(flagVal == 1 &&nomalCount== 0){
		parent.layer.alert("该服务单已经标记为刷单,请不要重复操作!",{icon:7});
		return false;
	}
	if(flagVal == 0 &&flagCount== 0){
		parent.layer.alert("该服务单已经标记为正常,请不要重复操作!",{icon:7});
		return false;
	}
	$.ajax({  
         type:'POST',      
	     url:url,  
	     data:{'orderids':ids,'flag':flagVal},  
	     cache:false,  
	     dataType:'json',  
	     success:function(data){  
		    if(data.success){
		    	parent.layer.alert(data.result);
		    	search();
				}else{
				 alert(data.result);
				}
	     }  
		}); 
}

//修改结算标识
function modifySettlement(v){
	var ids ="";
	var notCount = 0;//不结算个数
	var nomalCount = 0;//正常个数
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length==0){
		  parent.layer.alert("请选择要操作的服务单！",{icon:7});
		  return false;
	  }
	for(var i=0; i<rows.length; i++){
		if(rows[i].isSettlement == 1){
			parent.layer.alert("服务单已经结算,不能标记为不结算!",{icon:7});
			return false;
		}
		//判断订单是否处于暂停状态
		if(rows[i].serviceStatus == 0){
			parent.layer.alert("选择的订单中有处于暂停状态的订单，无法进行操作！",{icon:7});
		    return false;
		}
		if(rows[i].needSettlement == 0){
			nomalCount++;
		}else{
			notCount++;
		}
        ids+=rows[i].id+",";
    }  
	if(v == 1 &&nomalCount== 0){
		parent.layer.alert("该服务单已经标记为结算,请不要重复操作!",{icon:7});
		return false;
	}
	if(v == 0 &&notCount== 0){
		parent.layer.alert("该服务单已经标记为正常,请不要重复操作!",{icon:7});
		return false;
	}
	var ctx = $("#ctx").val();
	$.ajax({  
         type:'POST',      
	     url:ctx+'/buiNeworder/modifySettlement.do',  
	     data:{'orderids':ids,'needSettlement':v},  
	     cache:false,  
	     dataType:'json',  
	     success:function(data){  
		    if(data.success){
		    	parent.layer.alert(data.result);
		    	search();
				}else{
				 alert(data.result);
				}
	     }  
		}); 
}

//批量刷单
function toBatchbrush(){
	var ctx = $("#ctx").val();
	parent.layer.open({
		type: 2,
		area: [550+'px', 500+'px'],
		fix: false, //不固定
		shade:0.4,
		title:"批量刷单",
		content:[ctx+"/buiNeworder/toBatchbrush.do",'no'] ,
		success: function(layero, index){
		
	  }
});
}


//作废工单
function cancelOrder(page){
	var row = selectRow();
	if(row == 0){return false;}
	if(row.status==11){
		parent.layer.alert("订单已作废，不能重复操作！");
		return false;
	}
	if(row.origin == 0){
		//商家工单
		if(row.status!= 0 && row.status!= -4 && row.status!= -3){
			parent.layer.alert("商家订单只有在被退回、反审核或者未提交的状态才能作废");
			return false;
		}
	}
	if(row.origin == 6){
		//平台工单
		if(row.status!= -4 && row.status!= -1){
			parent.layer.alert("平台工单只有在未通过和反审核的状态才能作废");
			return false;
		}
	}
	
	parent.layer.open({
		type: 2,
		area: [1000+'px', 500+'px'],
		fix: false, //不固定
		shade:0.4,
		title:"作废",
		content:["buiAdminNeworder/ToCancelOrder.do?orderID="+row.id+'&page='+page,'no'] ,
		success: function(layero, index){
		
	  }
});
}
//跳转审核
function toCheckOrder(page,url){
	var row = selectRow();
	if(row == 0){
		return false;
	}else{
		if(row.status != -1 && row.status!= -2 && row.status!= -4 && row.status!=11){//未通过,未审核,反审核,已作废
			parent.layer.alert("只有【未审核】，【未通过】,【反审核】和【已作废】的服务单才可以审核！");
			return false;
		}
		if(row.payMode == 2 && (row.status == -1 || row.status == -4 || row.status == 11) && row.tmallDirectly !=1) {
			parent.layer.alert("预付商家，需商家重新下单并支付!");
			return false;
		}
	}
	
	parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '审核服务单',
        content:url+'?id='+row.id+'&page='+page,
        area: arrLayerPart,
        
});
}

//订单便签
function addOrderNote(){
	var id = selectid();
	if(id==0){return false;}
		parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '服务单内部便签',
        content:'ordernote/list.do?orderId='+id,
        area: ['800px', '450px'],
        
});
}
//取消审核
function cancelCheck(page){
	var row = selectRow();
	if(row == 0){
		return false;
		}else{
			if(row.status == 8 || row.status==7 || row.status==11|| row.status==-4 || row.status==-3 || row.status==-1){
				parent.layer.alert("已作废，未通过，被退回，反审核，待完成和已完成的工单不能取消审核!");
				return false;
			}else{
				if(row.parentID != null || row.isMerge ==1){
					parent.layer.confirm("子服务单或合并单取消审核,需要修改父服务单信息,确定要继续吗？",function(){
						var parentID = "";
						if(row.isMerge ==1){
							parentID = row.id;//合并单
						}else{
							parentID = row.parentID; //子服务单
						}
						parent.layer.open({
					        type: 2,
					        shade: 0.4,
					        title: '子服务单取消审核',
					        content:'neworderCheck/toCancelcheckSuborder.do?parentID='+parentID,
					        area: ['1000px', '450px'],
					         
					});
					});
				}else{
					parent.layer.open({
				        type: 2,
				        shade: 0.4,
				        title: '取消审核',
				        content:'neworderCheck/toCancelCheck.do?id='+row.id,
				        area: arrLayerPart,
				        
				});
				}
			}
		}
	
}
//反审核
function backCheck(){
	var row = selectRow();
	if(row == 0){
		return false;
		}else{
			if(row.status!= -3){
				parent.layer.alert("只有被退回的订单才可以反审核!");
				return false;
			}else{
				if(row.origin!= 6 && row.origin!= 1 ){
					parent.layer.alert("只有平台订单或者天猫订单才可以反审核!");
					return false;
				}else{
					parent.layer.open({
				        type: 2,
				        shade: 0.4,
				        title: '反审核',
				        content:'neworderCheck/toBackOrder.do?id='+row.id,
				        area: arrLayerPart,
				        
				});
			}
		}
	}
}

//退回到配单
function backToNoworker(page){
	var row = selectRow();
	if(row == 0){
		return false;
	}
	/*if(row.status != 15){
		parent.layer.alert("只有被放弃的服务单才能退回到配单");
		return false;
	}*/
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: '退回到配单',
	        content:'neworderAssign/toBackToNoworker.do?id='+row.id+'&page='+page,
	        area: arrLayerPart,
	        
	});
}

//退回到派单
function backToAssign(page){
	var row = selectRow();
	if(row == 0){
		return false;
	}else{
		if(row.status != 18 && row.status != 6&& row.status != 4&& row.status != 17 ){//再上门,待签到,待预约,预约失败
			parent.layer.alert("只有[待预约],[预约失败],[再上门]和[待签到]的服务单才能退回到派单!");
		}else{
			parent.layer.open({
		        type: 2,
		        shade: 0.4,
		        title: '退回到派单',
		        content:'neworderContact/toBackToAssign.do?id='+row.id+'&page='+page,
		        area: arrLayerPart,
		        
		});
	}
	}
}

//派工
function paigong(page){
	var row = selectRow();
	if(row == 0){
		return false;
	}else{
		if(row.status != 1 && row.status != 2 && row.status != 3 && row.status != 13 && row.status != 14 && row.status != 15 && row.status != 16 ){
			//已审核,待派单,待抢单,接单失败,被放弃,待接单
			parent.layer.alert("只有[已审核],[待派单],[配单失败],[接单失败],[被放弃],[待接单],[待抢单]的服务单才可以派工！");
			return false;
		}else{
			if(page == "push"){
				var title = "紧急派工";
			}else{
				var title = "派工";
			}
			parent.layer.open({
		        type: 2,
		        shade: 0.4,
		        title: title,
		        //content:'neworderAssign/topaiGong.do?id='+row.id+'&page='+page,//2017-03-28同一派工和推送操作，统一使用推送界面
		        content:'neworderAssign/toPushWorkerApp.do?id='+row.id+'&page='+page+'&actype=1',//actype=1代表派工，推送界面限制只能选择一个工人，并且不自动加载核心工人
		        area: arrLayerPart,
		        
		});
		}
	}
}

//派单
function dispatchOrder(page){
	var row = selectRow();
	if(row == 0){return false;}
	parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '派单',
        content:'neworderAssign/ToDispatchOrder.do?id='+row.id+'&page='+page,
        area: arrLayerPart,
        
	});
}

//推送至工人APP
function pushWorkerApp(page){
	var row = selectRow();
	if(row == 0){return false;}
	parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '派单',
        content:'neworderAssign/toPushWorkerApp.do?id='+row.id+'&page='+page,
        area: arrLayerPart,
        
	});
}

//调整服务价格
function AdjustServicePrice(url){
	var row = selectRow();
	if(row == 0){return false;}
	/*if(row.tmallDirectly == 1){
		parent.layer.alert("天猫直营订单，只能通过【添加天猫调整单】进行价格调整！");
		return false;
	}*/
	if(row.status <1 || row.status == 8 || row.status == 11  || row.status == 12){
		parent.layer.alert("未审核通过或已删除作废的不能调整服务价");
		return false;
	}
	if(row.parentID != null && row.parentID != ""){
		parent.layer.alert("不能单独对子订单进行调价，请选择其合并单进行调整！");
		return false;
	}
	layer.open({
        type: 2,
        shade: 0.4,
        title: '调整服务价格',
        content:url+"?id="+row.id,
        area: ['850px', '500px'],
	});
}
//追单
function chaseOrder(){
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length == 0){
		parent.layer.alert("请选择要操作的服务单！");
    	return false;
	}
    if(rows.length > 1){
    	parent.layer.alert("只能选择一条服务单！");
    	return false;
    }
	var serviceType= rows[0].serviceType;
	if(serviceType == 3){
		parent.layer.alert("测量订单不能追单！");
    	return false;
	}
	var id = rows[0].id;
	parent.layer.open({
			type: 2,
			area: arrLayerPart,
			fix: false, //不固定
			shade:0.4,
			title:"追单",
			content:["neworderAssign/toChaseOrder.do?orderid="+id] ,
			success: function(layero, index){
			
		  }
	});
}
//复制服务单
function copyOrder(page,url){
	var row = selectRow();
	if(row == 0 ){
		return false;
	}
	if(row.origin == 0 || row.origin == 5){
		parent.layer.alert("网络订单和商家订单不能复制");
		return false;
	}
	if(row.payMode == 2){
		parent.layer.alert("该商家支付方式为“预付”，需商家亲自下单并进行支付");
		return false;
	}
	if(row.sellerPayMode == 2){
		parent.layer.alert("该商家支付方式为“预付”，需商家亲自下单并进行支付");
		return false;
	}
	self.location=url+"?id="+row.id+"&page="+page;
	
}

//催单
function orderReminder(){
	var row = selectRow();
	if(row == 0){return false;}
	if(row.status == 11){
	 	parent.layer.alert("【已作废】状态的服务单,不能进行发起催单！",{icon:7});
		return false;
	}
	parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '催单',
        content:'reminder/toreminderstart.do?orderId='+row.id,
        area: ['800px', '400px'],
        
	});
}
//投诉
function orderComplaint(){
	var row = selectRow();
	if(row == 0){return false;}
	if(row.status == 11){
	 	parent.layer.alert("【已作废】状态的服务单,不能进行发起投诉！",{icon:7});
		return false;
	}
	parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '投诉',
        content:'complaint/tocomplaintstart.do?orderId='+row.id,
        area: ['800px', '400px'],
        
	});
}
//发起作废申请
function submitCancelOrder(){
	parent.layer.alert("正在抓紧研发中，敬请期待！");
	/*
	var row = selectRow();
	if(row == 0){return false;}
	parent.layer.open({
        type: 2,
        shade: 0.4,
        title: '派单',
        content:'neworderAssign/ToDispatchOrder.do?id='+row.id,
        area: ['1000px', '800px'],
        
	});
	*/
}

//发起售后
function startafterservice(url){
	var row = selectRow();
	if(row == 0){
		return false;
	}
	var status = row.status;
	if(status != 4 && status != 6 && status != 7 && status != 8){
		parent.layer.alert("【待预约】,【待签到】,【待完成】和【已完成】状态的服务单才能发起售后!");
		return false;
	}
	/*if(status != 8){
		parent.layer.alert("只有【已完成】状态的服务单才能发起售后!");
		return false;
	}*/
	var asStatus = row.asStatus;
	if(asStatus == 0 || asStatus == 1){
		parent.layer.alert("服务单售后完结后才能再次发起售后!");
		return;
	}
	var id = row.id;
	parent.layer.open({
			type: 2,
			area: [800+'px', 600+'px'],
			fix: false, //不固定
			shade:0.4,
			title:"发起售后",
			content: url+"/tostart.do?orderID="+id,
			success: function(layero, index){
		   }
	   });
		/*$.ajax({
        url : url+"/tostartcheck.do?orderID="+id,
        data :'' ,
		type : "post",
		success : function(data) {	
			if(data.result){//成功
				parent.layer.open({
			  			type: 2,
			  			area: [800+'px', 600+'px'],
			  			fix: false, //不固定
			  			shade:0.4,
			  			title:"发起售后",
			  			content: url+"/tostart.do?orderID="+id,
			  			success: function(layero, index){
			  		   }
	     		   });
			}else{//失败
				parent.layer.alert(data.errinfo);
			}
		},
		error : function(data) {
			parent.layer.alert("请求失败，请检查网络！");
		}
     });	*/		

}	



//获取一级类目
function getFirstGoodsType(){
	 	//服务标题
        var t = $("#classId").combotree("tree");
        if (t != null && t != undefined) {
            var node = t.tree("getSelected");
            if (node != null) {
                var topNode = getTopParnetNode(t, node);
                return topNode.id;
            }
        }
	}
//tree获取顶级父节点
	function getTopParnetNode(objtree, subnode) {
	    var pnode = objtree.tree("getParent", subnode.target);
	    if (pnode == null) {
	        return subnode;
	    } else {
	        return getTopParnetNode(objtree, pnode);
	    }
	}
	
	//未预约页面预约倒计时
	function countDown(value,row,index){
		//var timeStamp = dateTimeFun(row.yuyueEndTime);//ie不识别new Date('yyyy-mm-dd');格式日期转换
		var timeStamp = row.yuyueEndTime;
		var rowid=row.id.replace("\{","").replace("\}","");
		var state = row.statusStr;
		try{
			showEndtime(timeStamp,'timesId'+rowid,1,state);
		}catch(e){
			//兼容老数据,此次会报异常,暂未处理
			//alert(timeStamp+"//"+row.id);};
		}
		var strHtml ='<div id="timesId'+rowid+'" style="color:red"></div>';
	
		return strHtml;
	 
	}
	
	//未审核页面预约倒计时
	function checkcountDown(value,row,index){
		//var timeStamp = dateTimeFun(row.yuyueEndTime);//ie不识别new Date('yyyy-mm-dd');格式日期转换
		var timeStamp = row.yuyueEndTime;
		var rowid=row.id.replace("\{","").replace("\}","");
		try{
			showEndtime(timeStamp,'timesId'+rowid,3);
		}catch(e){
			//兼容老数据,此次会报异常,暂未处理
			//alert(timeStamp+"//"+row.id);};
		}
		var strHtml ='<div id="timesId'+rowid+'" style="color:red"></div>';
	
		return strHtml;
	 
	}
	//上门倒计时
	function serviceCountDown(value,row,index){
		//var timeStamp = dateTimeFun(row.serviceTime);//ie不识别new Date('yyyy-mm-dd');格式日期转换
		var timeStamp = row.serviceTime;
		var rowid=row.id.replace("\{","").replace("\}","");
		try{
			showEndtime(timeStamp,'timesId'+rowid,2);
		}catch(e){
			//兼容老数据,此次会报异常,暂未处理
			//alert(timeStamp+"//"+row.id);};
		}
		var strHtml ='<div id="timesId'+rowid+'" style="color:red"></div>';
	
		return strHtml;
	 
	}	
	//上门时间
	function showServiceTime(value,row,index){
		var timeStamp = dateTimeFun(row.serviceTime);//ie不识别new Date('yyyy-mm-dd');格式日期转换
		var rowid=row.id.replace("\{","").replace("\}","");
		var strHtml =timeStamp;
		try{
			if(row.isServiceTime==1){
				strHtml='<font style="color:red">'+strHtml+'</font>';
			}
		}catch(e){
			//兼容老数据,此次会报异常,暂未处理
		}
		return strHtml;
	 
	}
	
	
	//倒计时的实现 2016 8 31 zhujianfeng add 		
	function toTimes(n){
	return n = n < 10 ? '0'+n : n+'';	
	}
	function showEndtime(timeStamp,id,type,state){
		//console.log(timeStamp)
		if(timeStamp==''||timeStamp==undefined||timeStamp==null){return false;}
		var timer=null;
		var countDown = function(){
			var endTime=new Date(timeStamp);
			var nowTime= new Date();
			var timeDiff=parseInt((endTime.getTime()-nowTime.getTime())/1000);
			
			if(timeDiff < 0){
				
				clearInterval(timer);
				if("未签收" == state){					
					$('#'+id).html("");					
				}else{
					if(type == 1){
						$('#'+id).html('超时未确认');
					}else if(type == 3){
						$('#'+id).html('预约超时');
					}else{
						$('#'+id).html('签到超时');
					}
				}
				
				return;
			}else{
				if("未签收" == state){					
					$('#'+id).html("");					
				}else{
					var day=parseInt(timeDiff/(24*60*60));
					var hour=parseInt(timeDiff/(60*60)%24);
					var minutes=parseInt(timeDiff/60%60);
					var seconds=parseInt(timeDiff%60);
					$('#'+id).html(day + '天' +toTimes(hour)+'小时' + toTimes(minutes) + '分钟' + toTimes(seconds) + '秒');							
				}																
			}
	};
		countDown();
		timer=window.setInterval(countDown,1000);
	
	}
	
	//查询服务单详情
	function showOrderMsg(value,row,index){
		var isMerge = row.isMerge;
		var orderID = row.id;
		if (isMerge == 1) {
			var str="<a style=' display: inline-block;float:left;' href='javascript:showOrder(\""+orderID+"\");'>"+value+"</a> "+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>合</div>";
		}else{
			var str='<a style=" display: inline-block;float:left;" href="javascript:showOrder(\''+orderID+'\');">'+value+'</a> ';
		}
		var celiangOrderID = row.celiangOrderID;
		if(celiangOrderID != undefined && celiangOrderID != null && celiangOrderID != ""){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>测</div>";
		}
		if(row.hasExtra > 0 && row.isAdjust > 0){
			str += "<div data-p1="+index+" style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:#5bc0de;color:#fff'>调</div>"
		}
		if(row.origin == 1){
			str += "<div data-p1="+index+" style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;color:#fff'>店</div>"
		}
    	return str;
    }
	
	function showOrderMsg1(value,row,index){
		var isMerge = row.isMerge;
		var orderID = row.id;
		var str='<a style=" display: inline-block;float:left;" href="javascript:showOrder(\''+orderID+'\');">'+value+'</a> ';
		if (isMerge == 1) {
			str += "</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>合</div>";
		}else{
		}
		var celiangOrderID = row.celiangOrderID;
		if(celiangOrderID != undefined && celiangOrderID != null && celiangOrderID != ""){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>测</div>";
		}
		if(row.serviceStatus == 0){
			str += "<div data-p1="+index+" class='stop' style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:orange;float:left;color:#fff'>停</div>";
		}
		if(row.isAdjust > 0 || row.hasExtra > 0){
			str += "<div data-p1="+index+" style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:#5bc0de;color:#fff'>调</div>"
		}
		if(row.origin == 1){
			str += "<div data-p1="+index+" style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;color:#fff'>店</div>"
		}
    	return str;
    }
	
	//调整单查询服务单详情
	function showOrderMsg2(value,row,index){
		var isMerge = row.isMerge;
		var orderID = row.orderID;
		var str='<a style=" display: inline-block;float:left;" href="javascript:showOrder(\''+orderID+'\');">'+value+'</a> ';
		if (isMerge == 1) {
			str += "</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>合</div>";
		}else{
		}
		var celiangOrderID = row.celiangOrderID;
		if(celiangOrderID != undefined && celiangOrderID != null && celiangOrderID != ""){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>测</div>";
		}
		if(row.serviceStatus == 0){
			str += "<div data-p1="+index+" class='stop' style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:orange;float:left;color:#fff'>停</div>";
		}
    	return str;
    }
	
	//商家后台服务单展示
	function sellerOrderMsg(value,row,index){
		var isMerge = row.isMerge;
		var orderID = row.id;
		var str=value;
		if(row.serviceStatus == 0){
			str = "<div data-p1="+index+" class='stop' style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:orange;float:left;color:#fff'>停</div>" + str;
		}
		if(row.isAdjust > 0){
			str += "<div data-p1="+index+" style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:#5bc0de;color:#fff'>调</div>"
		}
    	return str;
	}
	
	//财务模块查询订单详情
	function financeOrderMsg(value,row,index){
		var orderID = row.orderID;
		var str='<a style=" display: inline-block;float:left;" href="javascript:showOrder(\''+orderID+'\');">'+value+'</a> ';
		if(row.isAdjust > 0){
			str += "<div data-p1="+index+" style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:#5bc0de;color:#fff'>调</div>"
		}
		if(row.reviewType == 1){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;color:#fff'>复核</div>";
		}
		var celiangOrderID = row.CeliangOrderID;
		if(celiangOrderID != undefined && celiangOrderID != null && celiangOrderID != ""){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>测</div>";
		}
    	return str;
	}
	
	//财务模块查询订单详情
	function workerFinanceOrderMsg(value,row,index){
		var orderID = row.orderID;
		var str='<a style=" display: inline-block;float:left;" href="javascript:showOrder(\''+orderID+'\');">'+value+'</a> ';
		if(row.isAdjust > 0){
			str += "<div data-p1="+index+" style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:#5bc0de;color:#fff'>调</div>"
		}
		if(row.workerReviewType == 1){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;color:#fff'>复核</div>";
		}
		var celiangOrderID = row.CeliangOrderID;
		if(celiangOrderID != undefined && celiangOrderID != null && celiangOrderID != ""){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>测</div>";
		}
		var afterServiceID = row.afterServiceID;
		if(afterServiceID != undefined && afterServiceID != null && afterServiceID != ""){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>售</div>";
		}
    	return str;
	}
	
	//详情浮动框方法  des：标题名，width：宽度
	function createStoptip(des,width){
		$('#dg').datagrid('getPanel').find('.stop').each(function(){
			var index = parseInt($(this).attr('data-p1'));
			$(this).tooltip({
				content: $('<div style ="padding:5px;"></div>'),
				onUpdate: function(cc){
					var row = $('#dg').datagrid('getRows')[index];
					var content = '<div>'+des+'<p>';
					var stopsingleRemark = row.stopsingleRemark;
					if(stopsingleRemark == undefined || stopsingleRemark == null){
						stopsingleRemark = "";
					}
					content += '<span>'+stopsingleRemark+'</span>';
					content += '</p></div>';
					cc.panel({
						width:width,
						content:content
					});
				},
				position:'top'
			});
		});
	}
	function showOrder(orderID){
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: '查看服务单',
	        content:'buiAdminNeworder/toOrderMsg.do?orderID='+orderID,
	        area: arrLayerPart	        
		});
	}
	
	function showSellerOrder(orderID){
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: '查看服务单',
	        content:'buiAdminNeworder/sellerToOrderMsg.do?orderID='+orderID,
	        area: arrLayerPart	        
		});
	}
	
	//调整单查询服务单详情
	function showSellerOrderMsg2(value,row,index){
		var isMerge = row.isMerge;
		var orderID = row.orderID;
		var str='<a style=" display: inline-block;float:left;" href="javascript:showSellerOrder(\''+orderID+'\');">'+value+'</a> ';
		if (isMerge == 1) {
			str += "</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>合</div>";
		}else{
		}
		var celiangOrderID = row.celiangOrderID;
		if(celiangOrderID != undefined && celiangOrderID != null && celiangOrderID != ""){
			str += "<div style='display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>测</div>";
		}
		if(row.serviceStatus == 0){
			str += "<div data-p1="+index+" class='stop' style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:orange;float:left;color:#fff'>停</div>";
		}
    	return str;
    }
	
	//每行紧急标记
	function markValue(value,row,index){
    	var mark = row.mark;
    	var flag = row.flag;
    	if(mark == 1 && flag==0){
    		var strHtml = "<span style=' display: inline-block;float:left;'>"+value+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>急</div>";
    		return strHtml;
    	}else if(mark == 0 && flag==1){
    		var strHtml = "<span style=' display: inline-block;float:left;'>"+value+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:gray;float:left;color:#fff'>刷</div>";
    		return strHtml;
    	}else if(mark == 1 && flag==1){
    		var strHtml = "<span style=' display: inline-block;float:left;'>"+value+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>急</div>"+"<div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:gray;float:left;color:#fff'>刷</div>";
    		return strHtml;
    	}else if(mark == 0 && flag==2){
    		var strHtml = "<span style=' display: inline-block;float:left;'>"+value+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:gray;float:left;color:#fff'>取消</div>";
    		return strHtml;
    	}else if(mark == 1 && flag==2){
    		var strHtml = "<span style=' display: inline-block;float:left;'>"+value+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>急</div>"+"<div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:gray;float:left;color:#fff'>取消</div>";
    		return strHtml;
    	}else{
    		return value;
    	}
    }
	
	function sellerFlagValue(value,row,index){
		var flag = row.flag;
		if(flag == 1){
			var strHtml = "<span style=' display: inline-block;float:left;'>"+value+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:gray;float:left;color:#fff'>刷</div>";
    		return strHtml;
		}else{
			return value;
		}
	}
	
	//项目调整项
	function orderCosts(){
	    	var row = selectRow();
	    	if(row == 0){
	    		return false;
	    	}
	    	if(row.goodsCommentStatus == 1){
	    		parent.layer.alert("订单已好评,不允许添加调整项!");
	    		return false;
	    	}
	    	if(row.isSettlement == 1){
	    		parent.layer.alert("订单已结算,不允许添加调整项!");
	    		return false;
	    	}
	    	
	    	if(row.tmallDirectly == 1){
	    		parent.layer.confirm("该订单是直营单，建议【添加天猫调整单】调整商家价格，确定要继续吗？",function(){
	    			parent.layer.closeAll('dialog');
	    	    	parent.layer.open({
	    	        type: 2,
	    	        fix: false,
	    	        shade: 0.4,
	    	        title: '调整单管理',
	    	        content: ["neworderToCompleted/toOrderCosts.do?id="+row.id,'no'],
	    	        area: ['1200px', '600px'],
	    	        cancel: function(index){
	    	        	var listFrame =$('#iframe_box', window.parent.document).find('.show_iframe:visible').find('iframe');
	    	        	listFrame[0].contentWindow.search();
	    	          }

	    	    	}); 
	    	});
	    	}else{
	    		parent.layer.open({
	    	        type: 2,
	    	        fix: false,
	    	        shade: 0.4,
	    	        title: '调整单管理',
	    	        content: ["neworderToCompleted/toOrderCosts.do?id="+row.id,'no'],
	    	        area: ['1200px', '600px'],
	    	        cancel: function(index){
	    	        	var listFrame =$('#iframe_box', window.parent.document).find('.show_iframe:visible').find('iframe');
	    	        	listFrame[0].contentWindow.search();
	    	          }

	    	    	}); 
	    	}
	    }
	
	//工单批量导入
	function batchImport(){
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: '批量导入服务单',
	        content:'buiAdminNeworder/toOrderImport.do',
	        area: ['800px', '450px'],
	        
		});
	}
	
	//工单异常处理
	function exceptionHandle(){
		var row = selectRow();
		if(row == 0){
			return false;
		}
		if(row.status == 8 || row.status == 11){
			parent.layer.alert("【已完成】和【已作废】状态的订单不能进行异常处理!");
			return false;
		}
		/*if(row.origin == 5){
			parent.layer.alert("天猫订单不能进行异常处理，请通过【取消审核】方式处理!");
			return false;
		}*/
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: '异常处理',
	        content:['buiNeworder/toExceptionHandle.do?orderID='+row.id+'&isMerge='+row.isMerge+'&tmallDirectly='+row.tmallDirectly,'no'],
	        area: ['350px', '200px'],
	        
		});
	}

	//获取物流信息
	function queryLogistics(url){
 		if($('#logistics-infor').is(':hidden')){
 			var logisticsName=$("#logisticsName").val();
 			if(logisticsName  == ""){
 			    parent.layer.alert("请选择物流公司！");
 				return false;
 			}
 			var logisticsInfo=$("#logisticsInfo").val();
 			if(logisticsInfo  == "" ){
 			    parent.layer.alert("请填写物流单号！");
 				return false;
 			}
 			$("#logistics-infor").html("");//删除以前的物流信息	
 	       	 $.ajax({  
 	       	         type:'post',      
 	       		     url:url,  
 	       		     data:{logisticsCompanyName : logisticsName , trackingNumber : logisticsInfo},  
 	       		     cache:false,  
 	       		     dataType:'json',  
 	       		     success:function(data){  
 	       		        if(data.result){
 		       		     	var i, datas = data.datas;
 		       		     	var htmlstr="<h5>物流详情:</h5>";
 						   	for (i = 0; i < datas.length; i++){
 								htmlstr=htmlstr+"<p>"+dateTimeFun(datas[i].statusTime)+datas[i].description+"</p>";
 						   	}
 						   	//alert(htmlstr);
 						   	$("#logistics-infor").html(htmlstr);
 						   	//alert(data.result+"//"+data.datas);
 						    $('#logistics-infor').show();
 				 			$('#viewLogistics').html('收起');
 					   	}else{
 					   		 parent.layer.alert("获取物流信息失败,原因："+data.error);
 					   	}
 	        		  }  
 	       	 });  	
 			
 		}else{
 			$('#logistics-infor').hide();
 			$('#viewLogistics').html('查看物流 ');
 		}
 	}

	//获取物料
	function accessory(url){
		var obj = $("#accessoryId");
		obj.html('<option value="">请选择</option>');
		
			$.ajax({
   			type:"post",
   	    	url:url,
   	    	dataType:"json",
   	    	success:function(data){
   	            for(var i=0;i<data.length;i++){
   	            	var m = data[i];
   	                obj.append('<option value="'+m.id+'">' +m.name+ '</option>');
   	            }
   	    	}
   		});
		
	}
	//获取材料
	function material(url){
		var obj = $("#materialId");
		obj.html('<option value="">请选择</option>');
		var accessoryId = $("#accessoryId").val();
		
		if(accessoryId != ""){
    		$.ajax({
    			type:"post",
    	    	url:url+"?accessoryId="+accessoryId,
    	    	dataType:"json",
    	    	success:function(data){
    	            for(var i=0;i<data.length;i++){
    	            	var m = data[i];
    	                obj.append('<option value="'+m.id+'" etalon="'+m.formatName+'">' +m.valueName+ '</option>');
    	            }
    	            obj.val(data[0].id);
    	            $("#materialId").trigger("change");
    	    	}
    		});
		}else{
			$("#colorId").html('<option value="">请选择</option>');
			$("#sellerId").html('<option value="">请选择</option>');
		}
	}
	//获取颜色
	function color(url){
		var obj = $("#colorId");
		obj.html('<option value="">请选择</option>');
		var accessoryId = $("#accessoryId").val();
		var materialId = $("#materialId").val();
		$.ajax({
			type:"post",
	    	url:url+"?accessoryId="+accessoryId+"&materialId="+materialId,
	    	dataType:"json",
	    	success:function(data){
	            for(var i=0;i<data.length;i++){
	            	var m = data[i];
	                obj.append('<option value="'+m.id+'">' +m.valueName+ '</option>');
	            }
	            obj.val(data[0].id);
	            $("#colorId").trigger("change");
	    	}
		});
	}
	//获取商家
	function seller(url){
		var obj = $("#sellerId");
		obj.html('<option value="">请选择</option>');
		var accessoryId = $("#accessoryId").val();
		var materialId = $("#materialId").val();
		var colorId = $("#colorId").val();
		$.ajax({
			type:"post",
	    	url:url+"?accessoryId="+accessoryId+"&materialId="+materialId+"&colorId="+colorId,
	    	dataType:"json",
	    	success:function(data){
	            for(var i=0;i<data.length;i++){
	            	var m = data[i];
	                obj.append('<option value="'+m.id+'" price="'+m.supplierPrice+'">' +m.seller+ '</option>');
	            }
	            obj.val(data[0].id);
	    	}
		});
	}
	//添加一行辅料
	function add(){
		var accessory = $("#accessoryId");
		var accessoryId = accessory.val();
		if(accessoryId == ""){
			parent.layer.alert("请选择辅料");
			return;
		}
		var material = $("#materialId");
		var materialId = material.val();
		if(materialId == ""){
			parent.layer.alert("请选择材质");
			return;
		}
		var color = $("#colorId");
		var colorId = color.val();
		if(colorId == ""){
			parent.layer.alert("请选择颜色");
			return;
		}
		var seller = $("#sellerId");
		var sellerId = seller.val();
		if(sellerId == ""){
			parent.layer.alert("请选择供应商");
			return;
		}
		var shipper = $("#shipper").val();
		if(shipper == ""){
			parent.layer.alert("请选择发货方");
			return;
		}
		
		var accessory_name = accessory.find("option:selected").text();
		var material_name = material.find("option:selected").text();
		var color_name = color.find("option:selected").text();
		var seller_name = seller.find("option:selected").text();
		var etalon = material.find("option:selected").attr("etalon");
		var price = seller.find("option:selected").attr("price");
		
		var obj = { 
				    "fuliaoID": accessoryId, 
				    "materialID": materialId, 
				    "colorID": colorId,
				    "supplierID": sellerId,
				    "name": accessory_name, 
				    "materialName": material_name,
				    "colorName": color_name,
				    "remark": "",
				    "fuliaoCount": 0,
				    "formatInfoRemark": etalon,
				    "delete": "",
				    "supplierName": seller_name,
				    "isFromSupplier": 1,
				    "logisticsPrice": 0,
				    "supplierPrice": price ,
				    "shipper":shipper
				    };
		appendRowAccessory(obj);
	}
	function appendRowAccessory(obj){
		var data = $("#dg-fuliao").datagrid('getRows');
        var flag = true;
        for (var i = 0; i < data.length; i++) {
            var d = data[i];
            if (d.fuliaoID == obj.fuliaoID && d.materialID == obj.materialID && d.colorID == obj.colorID) {
                flag = false;
                break;
            }
            if(d.supplierID != obj.supplierID && obj.supplierID == "42616fbc9cd54039a172a5b595eb2503"){
            	parent.layer.alert("请选择其他供应商或供应商全为工人");
            	flag = false;
                return false;
            }
        }
        if (flag) {
            $("#dg-fuliao").datagrid("appendRow", obj);
        }
	}
	//选择组合材料
	function selectCombinationAccessory(url){
		parent.layer.open({
			type: 2,
			area: [1000+'px', 650+'px'],
			fix: false, //不固定
			shade:0.4,
			title:"选择组合材料",
			content: url + "?iframeName=" + window.name,
			success: function(layero, index){
			
		  	}
		});
	}
	//添加组合辅料
	function appendCombinationAccessory(url,iframeName){
		var shipper = $("#shipperType").val();
		if(shipper == undefined || shipper == null || shipper == ""){
			parent.layer.alert("请选择发货方");
			return;
		}
		var rows = $("#dg").datagrid('getSelections');
		var btn = $("#selectBtn");
		var combinationNum = "";
		if(rows.length == 0){
			parent.layer.alert("请选择组合材料");
			return;
		}else{
			btn.attr("disabled",true);
			for(var i=0;i<rows.length;i++){
				if(combinationNum == ""){
					combinationNum = rows[i].id;
				}else{
					combinationNum += "," + rows[i].id;
				}
			}
		}
		
		$.ajax({
			type:"post",
	    	url:url + "?ids=" + combinationNum,
	    	dataType:"json",
	    	success:function(data){
	    		var listFrame;
	    		if(iframeName == "" || iframeName == undefined || iframeName == null){
	    			listFrame = $('#iframe_box', window.parent.document).find('.show_iframe:visible').find('iframe');
	    		}else{
	    			listFrame = $('#'+iframeName, window.parent.document);
	    		}
	            for(var i=0;i<data.length;i++){
	            	var m = data[i];
	            	var obj = { 
	    				    "fuliaoID": m.accessoryId, 
	    				    "materialID": m.materialId, 
	    				    "colorID": m.colorId,
	    				    "supplierID": m.sellerId,
	    				    "name": m.accessory_name, 
	    				    "materialName": m.material_name,
	    				    "colorName": m.color_name,
	    				    "remark": "",
	    				    "fuliaoCount": m.accessory_count,
	    				    "formatInfoRemark": m.etalon,
	    				    "delete": "",
	    				    "supplierName": m.seller_name,
	    				    "isFromSupplier": 1,
	    				    "logisticsPrice": 0,
	    				    "supplierPrice": m.price ,
	    				    "shipper":shipper
	    				    };
	            	var flag = listFrame[0].contentWindow.appendRowAccessory(obj);
	            	if(flag == false){
	            		return;
	            	}
	            }
	            listFrame[0].contentWindow.showAmount();
	            //关闭页面
	            var index_ = parent.layer.getFrameIndex(window.name); //获取窗口索引
	    		parent.layer.close(index_);
	    	},
			error : function(result) {//调用失败
				btn.removeAttr("disabled");
			}
		});
		
	}
	//删除辅料
	  function DeleteFuliao(index) {
         $('#dg-fuliao').datagrid("deleteRow", index);
         setFuliaoInfo();
         $('#dg-fuliao').datagrid('loadData', jQuery.parseJSON($('#hffuliaoinfo').val()));//为了刷新每行的Index，因为删除按钮保存的一致是第一次加载时的index
	   }
	  //设置辅料
	  function setFuliaoInfo() {
        var data = $('#dg-fuliao').datagrid('getRows');
        var json = JSON.stringify(data);
        $('#hffuliaoinfo').val(json);//序列化json数据保存
    }
	//点击计算总价
	function OkEdit() {
	    EndEditAll();//先结束编辑状态
	    GetAmount();
	}
	//计算总价
	  function GetAmount() {
		    var data = $("#dg-fuliao").datagrid('getRows');
		    var amount = 0;
		    for (i = 0; i < data.length; i++) {
		        amount += accMul(parseInt(data[i].fuliaoCount), parseFloat(data[i].supplierPrice));
		    }
		    $("#totalPrice").text("总价：" + amount);
		}
		function accMul(arg1, arg2) {
		    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
		    try { m += s1.split(".")[1].length } catch (e) { }
		    try { m += s2.split(".")[1].length } catch (e) { }
		    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
       }
		function showAmount() {
		    var data = $("#dg-fuliao").datagrid('getRows');
		    var amount = 0;
		    for (i = 0; i < data.length; i++) {
		        amount += accMul(parseInt(data[i].fuliaoCount), parseFloat(data[i].supplierPrice));
		    }
		    if($("#totalPrice") != undefined){
		    	$("#totalPrice").text("总价：" + amount);
		    }
		    if($("#confirmSettlementAmount") != undefined){
		    	$("#confirmSettlementAmount").val(amount);
		    }
		}
		function undefinedConvertStr(obj){
			return obj == undefined?"":obj;
		}
		
	//一层弹出层关闭并局部刷新	
	function partialRefresh(){
		var index_ = parent.layer.getFrameIndex(window.name); //获取窗口索引
		var listFrame =$('#iframe_box', window.parent.document).find('.show_iframe:visible').find('iframe');
		listFrame[0].contentWindow.search();
		parent.layer.close(index_);
	}
	
	function partialRefresh2(){
		var index_ = parent.layer.getFrameIndex(window.name); //获取窗口索引
		var listFrame =$('#iframe_box', window.parent.document).find('.show_iframe:visible').find('iframe');
		listFrame[0].contentWindow.searchS();
		parent.layer.close(index_);
	}
	
	//两个弹出层，关闭子窗口刷新父窗口
	function closeRefresh(){
		//刷新父级弹框
		var iframe = $('.layui-layer-iframe', window.parent.document).eq(0).find('iframe');
		iframe.attr('src',iframe.attr('src'));
		var index_ = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index_);//关闭窗口
	}
	
	//商家单价展示
	function sellerMonovalentFun(value,row,index){
		if(row.sellerUnitPrice != 0 && row.sellerUnitPrice != undefined ){
			return row.sellerUnitPrice;
		}
		if(row.sellerRealPrice == undefined){
			row.sellerRealPrice = 0;
		}
		if(row.goodsCount == undefined){
			row.goodsCount = 0;
		}
		if(row.goodsCount == 0 && row.adjustAuantity > 0){
			return (Number(row.sellerRealPrice)/Number(row.adjustAuantity)).toFixed(2);
		}
		return (Number(row.sellerRealPrice)/Number(row.goodsCount)).toFixed(2);
	}
	
	//工人单价展示
	function workerMonovalentFun(value,row,index){
		if(row.workerUnitPrice != 0 && row.workerUnitPrice != undefined){
			return row.workerUnitPrice;
		}
		if(row.workerRealPrice == undefined){
			row.workerRealPrice = 0;
		}
		if(row.goodsCount == undefined){
			row.goodsCount = 0;
		}
		if(row.goodsCount == 0 && row.adjustAuantity > 0){
			return (Number(row.workerRealPrice)/Number(row.adjustAuantity)).toFixed(2);
		}
		return (Number(row.workerRealPrice)/Number(row.goodsCount)).toFixed(2);
	}
	
	//创建开始时间
	$('#createStartTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	//创建结束时间
	$('#createEndtTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	//服务开始时间
	$('#serviceStartFinishTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});		
	//服务结束时间
	$('#serviceEndFinishTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	
	//服务开始时间
	$('#serviceStartTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});		
	//服务结束时间
	$('#serviceEndTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	//评价开始时间
	$('#goodsCommentStartTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	//评价结束时间
	$('#goodsCommentEndTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	//人工结算开始时间
	$('#settlementStartTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	//人工结算结束时间
	$('#settlementEndTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	
	//签到开始时间
	$('#signInStartTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	//签到结束时间
	$('#signInEndTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	
	//预约时间
	$('#yuyueEndTime1').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	$('#yuyueEndTime2').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	//核销时间
	$('#tmallWriteOffTime1').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	$('#tmallWriteOffTime2').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	
	//签收时间
	$('#logisticsSignStartTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	$('#logisticsSignEndTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	
	//暂停时间
	$('#stopsingleStartTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});
	$('#stopsingleEndTime').datetimebox({  
	    required : false,  
	    onShowPanel:function(){  
	        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
	    }  
	});	
	
	
	function setDateTime0(id){
		$('#'+id).datetimebox({  
		    required : false,  
		    onShowPanel:function(){  
		        $(this).datetimebox("spinner").timespinner("setValue","0:0:0");  
		    }  
		});	
	}
	
	function goodsImgUrlFun(value,row,index){
		if(row.goodsImgUrl == undefined || row.goodsImgUrl == null || row.goodsImgUrl == ""){
			return "无";
		}else{
			return '<a href="'+row.goodsImgUrl+'" target="_blank">点击查看</a>'
		}
	}
	
	function goodsUrlFun(value,row,index){
		if(row.goodsUrl == undefined || row.goodsUrl == null || row.goodsUrl == ""){
			return "";
		}else{
			return '<a href="'+row.goodsUrl+'" target="_blank">点击查看</a>'
		}
	}
	//商家后台新增服务商品
	var windowWidth = $(window).width();
	var arrOnes=[]
	if(windowWidth<=1440){
		 arrOnes= ['850px','500px']
	}else{
		 arrOnes= ['1300px','500px']
	}
	function addServiceGoods(){
		var area=$("#area").val();
		if(area  == "" || area  == "0" ){
		    parent.layer.alert("请填写买家地址！");
			return false;
		}
		layer.open({
			type: 2,
			area:arrOnes,
			fix: false, //不固定
			shade:0.4,
			title:"直接添加服务商品",
			content:["serviceprice.do?topClassID="+$("#topClassID").val()+"&serviceTypeID="+$("#serviceTypeID").val()+"&sellerID="+$("#sellerID").val(),'yes'] ,
			success: function(layero, index){
			
		  }
		});
	}
	//商家后台的服务商品编辑
	function editServiceGoods(){
		var rows = $('#dg1').datagrid('getSelections');
		if(rows.length == 0){
			parent.layer.alert("请选择要修改的信息！",{icon:7});
	    	return false;
		}
	    if(rows.length > 1){
	    	parent.layer.alert("请选择单条信息！",{icon:7});
	    	return false;
	    }
	    var serviceGoods = rows[0].serviceGoods;
	    var goodsCount = rows[0].goodsCount;
	    var goodsInfo = rows[0].goodsInfo;
	    var goodsUrl = rows[0].goodsUrl;
	    var goodsImgUrl = rows[0].goodsImgUrl;
		var area=$("#area").val();
				if(area  == "" || area  == "0" ){
				    parent.layer.alert("请填写买家地址！");
					return false;
				}
				layer.open({
					type: 2,
					area: ['850px','500px'],
					fix: false, //不固定
					shade:0.4,
					title:"直接添加服务商品",
					content:["serviceprice.do?serviceGoods="+serviceGoods+"&type=edit"+"&goodsCount="+goodsCount+"&goodsInfo="+goodsInfo+"&goodsUrl="+goodsUrl+"&goodsImgUrl="+goodsImgUrl+"&sellerID="+$("#sellerID").val(),'yes'] ,
					success: function(layero, index){
				  }
				});
	}
	//商家后台删除服务商品
	function deleteGoods(){
		var rows = $('#dg1').datagrid('getSelections');//获取所有选中行
		if(rows.length==0){
		parent.layer.alert("请选择要删除的服务商品!");
		return false;
		}
		var total=Number($("#goodsCount").html());
		for ( var i = 0; i < rows.length; i++) {
			//重新计算商品价格
			total -= Number(rows[i]['goodsCount']); //获取商品数量
   			var index=$('#dg1').datagrid('getRowIndex',rows[i]);//获取选中行的index
			$('#dg1').datagrid('deleteRow',index);//根据index值删除
		}
		var rowsData = $('#dg1').datagrid('getRows');
		var minWorker=0;//工人最小起步价
		var maxSeller=0;//商家最大起步价
		var workerTotal=0;//工人总价
		var sellerTotal=0;//商家总价
		var isflag=true;
		for ( var i = 0; i < rowsData.length; i++) {
			var curentSellerPrice=Number(rowsData[i]['sellerRealPrice']);
			var curentWorkerPrice=Number(rowsData[i]['workerRealPrice']);
			sellerTotal += curentSellerPrice; //获取工人价
			workerTotal += curentWorkerPrice; //获取商家价
			
			var curentSellerStartPrice=Number(rowsData[i]['sellerStartPrice']);
			var curentWorkerStartPrice=Number(rowsData[i]['workerStartPrice']);
			if(isflag){//是否第一次进入循环
				minWorker = curentWorkerStartPrice;
				maxSeller = curentSellerStartPrice;
			}else{
				if(minWorker < curentWorkerStartPrice ){
					minWorker = curentWorkerStartPrice;
				}
				if(maxSeller < curentWorkerStartPrice){
					maxSeller = curentWorkerStartPrice;
				}
			}
		}
		if(workerTotal < minWorker){
			workerTotal=minWorker;
		}
		if(sellerTotal < maxSeller){
			sellerTotal=maxSeller;
		}
		
		$("#sellerStartPrice").val(maxSeller);
		$("#workerStartPrice").val(minWorker);
		$("#goodsCount").html(total);
		$("#serviceAmount").html(sellerTotal);
		var rows = $('#dg1').datagrid('getRows');//获取服务信息所有数据
		//重新展示小单费
		sellerFeeCalculation(rows);
		//清空一级类目
		var data=$('#dg1').datagrid('getData');
		if(data.rows.length == 0){
	  		$("#topClassID").val("");//全部删除则清空一级类目
		}
	}
	//平台编辑服务商品
	function adminEditServiceGoods(){
		var rows = $('#dg').datagrid('getSelections');
		if(rows.length == 0){
			parent.layer.alert("请选择要编辑的服务信息！",{icon:7});
	    	return false;
		}
	    if(rows.length > 1){
	    	parent.layer.alert("一次只能编辑一条服务信息！",{icon:7});
	    	return false;
	    }
	    var row = $('#dg').datagrid('getSelected');//获取当前页的数据行
	    var sellerId=$("#sellerId").val();
	    //跳转至设置服务信息页面
	    layer.open({
            type: 2,
            shade: 0.4, 
            title: '设置服务信息',
            content:'serviceGoodsClass.do?sellerId='+sellerId+'&type=edit'+'&goodsCount='+row.goodsCount,
            area: ['1000px', '650px'],
    		success:function(layero,index){
		        },
	        end:function(){
	            }
        });
	}
	//平台删除服务商品
	function amidnDeleteGoods(){
		var rows = $('#dg').datagrid('getSelections');//获取所有选中行
		if(rows.length==0){
		parent.layer.alert("请选择要删除的服务商品!");
		return false;
		}
		var total=Number($("#orderGoodsCount").val());
		for ( var i = 0; i < rows.length; i++) {
			//重新计算商品价格
			total -= Number(rows[i]['goodsCount']); //获取商品数量
   			var index=$('#dg').datagrid('getRowIndex',rows[i]);//获取选中行的index
			$('#dg').datagrid('deleteRow',index);//根据index值删除
		}
		var rowsData = $('#dg').datagrid('getRows');
		var minWorker=0;//工人最小起步价
		var maxSeller=0;//商家最大起步价
		var workerTotal=0;//工人总价
		var sellerTotal=0;//商家总价
		var materialExpenseTotal=0;//材料费
		var expenseTotal=0;//运费
		var isflag=true;
		for ( var i = 0; i < rowsData.length; i++) {
			var curentSellerPrice=Number(rowsData[i]['sellerRealPrice']);
			var curentWorkerPrice=Number(rowsData[i]['workerRealPrice']);
			sellerTotal += curentSellerPrice; //获取工人价
			workerTotal += curentWorkerPrice; //获取商家价
			
			var curentSellerStartPrice=Number(rowsData[i]['sellerStartPrice']);
			var curentWorkerStartPrice=Number(rowsData[i]['workerStartPrice']);
			
			var materialExpense=Number(rowsData[i]['materialExpense']);
			var expense=Number(rowsData[i]['expense']);
			if(rowsData[i]['materialExpense'] == undefined){
				materialExpense = 0;
			}
			if(rowsData[i]['expense'] == undefined){
				expense = 0;
			}
			materialExpenseTotal += materialExpense;
			expenseTotal += expense;
			
			if(isflag){//是否第一次进入循环
				minWorker = curentWorkerStartPrice;
				maxSeller = curentSellerStartPrice;
			}else{
				if(minWorker < curentWorkerStartPrice ){//工人价去最大值
					minWorker = curentWorkerStartPrice;
				}
				if(maxSeller < curentWorkerStartPrice){
					maxSeller = curentWorkerStartPrice;
				}
			}
		}
		if(workerTotal < minWorker){
			workerTotal=minWorker;
		}
		if(sellerTotal < maxSeller){
			sellerTotal=maxSeller;
		}
		
		$("#sellerStartPrice").val(maxSeller);
		$("#workerStartPrice").val(minWorker);
		$("#orderGoodsCount").val(total);
		$("#payAmount").val(workerTotal);
		$("#serviceAmount").val(sellerTotal);
		$("#materialExpenseTotal").val(materialExpenseTotal);
		$("#expenseTotal").val(expenseTotal);
		$("#totalcost").val(workerTotal + materialExpenseTotal + expenseTotal);
		var rows = $('#dg').datagrid('getRows');//获取服务信息所有数据
		//重新展示小单费
		feeCalculation(rows);
		//清空一级类目
		var data=$('#dg').datagrid('getData');
		if(data.rows.length == 0){
	  		$("#firstGoodsType").val("");//全部删除则清空一级类目
	  		$("#allserviceType").val("");//全部删除则清空一级类目
	  		$("#xiaodanfei").text("");
		}
		//重新展示毛利率
		$("#lilv").html(GetPercent(sellerTotal-(materialExpenseTotal + expenseTotal + workerTotal),sellerTotal));
		$("#lilv2").html(GetPercent(sellerTotal-(materialExpenseTotal + expenseTotal + workerTotal),sellerTotal));
	}
	
	//平台小单费计算展示
	function  feeCalculation(rows){
		var totalSellerPrice=0;//商家总价
		var totalWorkerPrice=0;//工人总价
		var startSellerPrice=0;//商家起步价
		var startWorkerPrice=0;//工人起步价
		var zJorderGoodsCount=0;//调整数量
		var isfirst=true;
		
		for(var i=0;i<rows.length;i++){
			var cSellerStart = Number(rows[i].sellerStartPrice);
			var cWorkererStart = Number(rows[i].workerStartPrice);
			if(isfirst){
				startSellerPrice = cSellerStart;
				startWorkerPrice = cWorkererStart;
				isfirst=false;
			}
			totalWorkerPrice += Number(rows[i].workerRealPrice);
			totalSellerPrice += Number(rows[i].sellerRealPrice);
			if(startSellerPrice < cSellerStart){//商家起步价取最大值
				startSellerPrice=cSellerStart;
			}
			if(startWorkerPrice < cWorkererStart){//工人起步价取最大值
				startWorkerPrice=cWorkererStart;
			}
			
			var adjustAuantity=Number(rows[i].adjustAuantity);
			zJorderGoodsCount+=adjustAuantity;
		}
		totalSellerPrice=$("#serviceAmount").val();
		totalWorkerPrice=$("#payAmount").val();			
		var sellerFee=0;
		var workerFee=0;
		if( startSellerPrice > totalSellerPrice ){
			sellerFee = startSellerPrice-totalSellerPrice;
		}
		if( startWorkerPrice > totalWorkerPrice ){
			workerFee= startWorkerPrice - totalWorkerPrice;
		}
		
		if(totalSellerPrice >0 && totalWorkerPrice > 0){
			if (workerFee > 0 || sellerFee > 0) {
				var msg="服务价低于起步价，将自动添加一个小单费，";
				if(sellerFee > 0){
					msg+= "商家价调整:" + sellerFee.toFixed(2)+";";
				}
				if(workerFee > 0){
					msg+= "工人价调整:" + workerFee.toFixed(2)+";";
				}
				$("#xiaodanfei").text(msg);
			} else {
				$("#xiaodanfei").text("");
			}
		}
		$("#zJorderGoodsCount").val(zJorderGoodsCount);
	}
	function  computedCalculation(rows){
		var totalSellerPrice=0;//商家总价
		var totalWorkerPrice=0;//工人总价
		var startSellerPrice=0;//商家起步价
		var startWorkerPrice=0;//工人起步价
		var zJorderGoodsCount=0;//调整数量
		var isfirst=true;
		
		for(var i=0;i<rows.length;i++){
			var cSellerStart = Number(rows[i].sellerStartPrice);
			var cWorkererStart = Number(rows[i].workerStartPrice);
			if(isfirst){
				startSellerPrice = cSellerStart;
				startWorkerPrice = cWorkererStart;
				isfirst=false;
			}
			totalWorkerPrice += Number(rows[i].workerRealPrice);
			totalSellerPrice += Number(rows[i].sellerRealPrice);
			if(startSellerPrice < cSellerStart){//商家起步价取最大值
				startSellerPrice=cSellerStart;
			}
			if(startWorkerPrice < cWorkererStart){//工人起步价取最大值
				startWorkerPrice=cWorkererStart;
			}
			
			var adjustAuantity=Number(rows[i].adjustAuantity);
			zJorderGoodsCount+=adjustAuantity;
		}
		
		var sellerFee=0;
		var workerFee=0;
		if( startSellerPrice > totalSellerPrice ){
			totalSellerPrice=startSellerPrice;
		}
		if( startWorkerPrice > totalWorkerPrice ){
			totalWorkerPrice=startWorkerPrice;
		}
		$("#payAmount").val(totalWorkerPrice);
		$("#serviceAmount").val(totalSellerPrice);
	}
	
	//商家后台小单费计算展示
	function  sellerFeeCalculation(rows){
		var totalSellerPrice=0;//商家总价
		var startSellerPrice=0;//商家起步价
		var isfirst=true;
		
		for(var i=0;i<rows.length;i++){
			var cSellerStart = Number(rows[i].sellerStartPrice);
			if(isfirst){
				startSellerPrice = cSellerStart;
				isfirst=false;
			}
			totalSellerPrice += Number(rows[i].sellerRealPrice);
			if(startSellerPrice < cSellerStart){//商家起步价取最大值
				startSellerPrice=cSellerStart;
			}
		}
		var sellerFee=0;
		if( startSellerPrice > totalSellerPrice ){
			sellerFee = floatSub(startSellerPrice,totalSellerPrice);
		}
		
		if (sellerFee > 0) {
	 	    var msg="服务价低于起步价，将自动添加一个小单费，";
	 	    if(sellerFee > 0){
	 	    	msg+= "商家价调整:" + sellerFee+";";
	 	    }
	        $("#xiaodanfei").text(msg);
	    } else {
	        $("#xiaodanfei").text("");
	    }
		$("#serviceAmount").html(floatAdd(totalSellerPrice,sellerFee));
	}
	function  computedCalculation(rows){
		var totalSellerPrice=0;//商家总价
		var totalWorkerPrice=0;//工人总价
		var startSellerPrice=0;//商家起步价
		var startWorkerPrice=0;//工人起步价
		var zJorderGoodsCount=0;//调整数量
		var isfirst=true;
		
		for(var i=0;i<rows.length;i++){
			var cSellerStart = Number(rows[i].sellerStartPrice);
			var cWorkererStart = Number(rows[i].workerStartPrice);
			if(isfirst){
				startSellerPrice = cSellerStart;
				startWorkerPrice = cWorkererStart;
				isfirst=false;
			}
			totalWorkerPrice += Number(rows[i].workerRealPrice);
			totalSellerPrice += Number(rows[i].sellerRealPrice);
			if(startSellerPrice < cSellerStart){//商家起步价取最大值
				startSellerPrice=cSellerStart;
			}
			if(startWorkerPrice < cWorkererStart){//工人起步价取最大值
				startWorkerPrice=cWorkererStart;
			}
			
			var adjustAuantity=Number(rows[i].adjustAuantity);
			zJorderGoodsCount+=adjustAuantity;
		}
		
		var sellerFee=0;
		var workerFee=0;
		if( startSellerPrice > totalSellerPrice ){
			totalSellerPrice=startSellerPrice;
		}
		if( startWorkerPrice > totalWorkerPrice ){
			totalWorkerPrice=startWorkerPrice;
		}
		$("#payAmount").val(totalWorkerPrice);
		$("#serviceAmount").val(totalSellerPrice);
	}
	
	//设置服务信息
	function setSercvie(rows){
		$("#service").html("");
		for ( var i = 0; i < rows.length; i++) {
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].goodName' value='"+rows[i].goodName+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].serviceGoods' value='"+rows[i].serviceGoods+"'/>");//服务商品id,关联bui_serviceprice表
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].goodsCount' value='"+rows[i].goodsCount+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].goodsTitle' value='"+rows[i].goodsTitle+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].serviceType' value='"+rows[i].serviceType+"'/>");
			if(rows[i].goodsInfo == undefined){
				rows[i].goodsInfo = "";
			}
			if(rows[i].goodsImgUrl == undefined){
				rows[i].goodsImgUrl = "";
			}
			if(rows[i].goodsUrl == undefined){
				rows[i].goodsUrl = "";
			}
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].goodsInfo' value='"+rows[i].goodsInfo+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].goodsImgUrl' value='"+rows[i].goodsImgUrl+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].goodsUrl' value='"+rows[i].goodsUrl+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].sellerRealPrice' value='"+rows[i].sellerRealPrice+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].workerRealPrice' value='"+rows[i].workerRealPrice+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].sellerBasePrice' value='"+rows[i].sellerBasePrice+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].wokerBasePrice' value='"+rows[i].wokerBasePrice+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].serviceGoodsType' value='"+rows[i].serviceGoodsType+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].sellerUnitPrice' value='"+rows[i].sellerUnitPrice+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].sellerStartPrice' value='"+rows[i].sellerStartPrice+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].workerUnitPrice' value='"+rows[i].workerUnitPrice+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].workerStartPrice' value='"+rows[i].workerStartPrice+"'/>");
			var materialExpense = 0;
			var expense = 0;
			if(rows[i].materialExpense != undefined){
				materialExpense = rows[i].materialExpense;
			}
			if(rows[i].expense != undefined){
				expense = rows[i].expense;
			}
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].materialExpense' value='"+materialExpense+"'/>");
			$("#service").append("<input type='hidden' name='ordergoods["+i+"].expense' value='"+expense+"'/>");
			if(rows[i].tmallID != undefined && rows[i].tmallID != ''){
				$("#service").append("<input type='hidden' name='ordergoods["+i+"].tmallID' value='"+rows[i].tmallID+"'/>");
			}
			if(rows[i].tmallDirectly != undefined && rows[i].tmallDirectly != ''){
				$("#service").append("<input type='hidden' name='ordergoods["+i+"].tmallDirectly' value='"+rows[i].tmallDirectly+"'/>");
			}
		}
			
	}
	
	function getLastMonthDate(){
		var date = new Date();
		return date.getFullYear() + "-" + (date.getMonth() < 10 ? "0"+date.getMonth() : date.getMonth()) + "-" + date.getDate() + " 00:00:00";
     }
	
	//平台新增订单时，已经选择了服务商品再次改变区域，将重新进行价格计算
	function changeArea(obj,url){
		var oldArea = $("#oldArea").val();
		var newArea = $(obj).val();
		if(oldArea != '' && oldArea != newArea){
			var rows = $('#dg').datagrid('getRows');
			if(rows.length != 0){
				var maxSeller = 0;
				var minWorker = 0;
				parent.layer.alert("已经添加了服务信息,修改服务地址,保存时会重新计算服务价!");
				for ( var i = 0; i < rows.length; i++) {
					computedByAreachange(rows[i],i,url,newArea,"dg");
				}
				//重新计算价格
				rows = $('#dg').datagrid('getRows');
				var sellerTotal=0;
				var workerTotal=0;
				var total = 0; 
				for (var i = 0; i < rows.length; i++) { 
					total += Number(rows[i]['goodsCount']); //获取商品数量
					sellerTotal += Number(rows[i]['sellerRealPrice']); //获取工人价
					workerTotal += Number(rows[i]['workerRealPrice']); //获取商家价
					var s=Number(rows[i]['sellerStartPrice']);
					var w=Number(rows[i]['workerStartPrice']);
					if(minWorker < w){//工人起步价取最大值
						minWorker=w;
					}
					if(maxSeller <  s){//商家起步价取最大值
						maxSeller= s;
					}
					 
				} 
				if(workerTotal < minWorker){
					workerTotal=minWorker;
				}
				if(sellerTotal < maxSeller){
					sellerTotal=maxSeller;
				}
				
				$("#sellerStartPrice").val(maxSeller);
				$("#workerStartPrice").val(minWorker);
				$("#payAmount").val(workerTotal);
				$("#serviceAmount").val(sellerTotal);
				//重新计算合计和小单费
				feeCalculation(rows);
			}
		}
		$("#oldArea").val(newArea);
	}
	
	//商家后台选择商品之后改变区域将重新进行价格计算
	function sellerChangeArea(obj,url){
		var oldArea = $("#oldArea").val();
		var newArea = $(obj).val();
		if(oldArea != '' && oldArea != newArea){
			var rows = $('#dg1').datagrid('getRows');
			if(rows.length != 0){
				var maxSeller = 0;
				var minWorker = 0;
				parent.layer.alert("已经添加了服务信息,修改服务地址,保存时会重新计算服务价!");
				for ( var i = 0; i < rows.length; i++) {
					computedByAreachange(rows[i],i,url,newArea,"dg1");
				}
				//重新计算价格
				rows = $('#dg1').datagrid('getRows');
				var sellerTotal=0;
				var workerTotal=0;
				var total = 0; 
				for (var i = 0; i < rows.length; i++) { 
					total += Number(rows[i]['goodsCount']); //获取商品数量
					sellerTotal += Number(rows[i]['sellerRealPrice']); //获取工人价
					workerTotal += Number(rows[i]['workerRealPrice']); //获取商家价
					var s=Number(rows[i]['sellerStartPrice']);
					var w=Number(rows[i]['workerStartPrice']);
					if(minWorker < w){//工人起步价取最大值
						minWorker=w;
					}
					if(maxSeller <  s){//商家起步价取最大值
						maxSeller= s;
					}
					 
				} 
				if(workerTotal < minWorker){
					workerTotal=minWorker;
				}
				if(sellerTotal < maxSeller){
					sellerTotal=maxSeller;
				}
				
				$("#sellerStartPrice").val(maxSeller);
				$("#workerStartPrice").val(minWorker);
				$("#serviceAmount").html(sellerTotal);
				//重新计算合计和小单费
				sellerFeeCalculation(rows);
			}
		}
		$("#oldArea").val(newArea);
	}
	
	
	//改变买家区域后重新计算价格
	function computedByAreachange(row,i,url,area,id){
			var n=row.serviceGoods;
			var sellerId=$("#sellerID").val();
			var goodscount = row.goodsCount;
			//计算价格
			 $.ajax({
			    	type:"post",
			    	url:url,
			    	async:false, 
			    	data:{
			    		"goodId":n,//商品id
			    		"goodCount":goodscount,//商品数量
			    		"sellerid":sellerId,//商家id
			    		"area":area//区域
			    	},
	    	success:function(data){
		    	if(data != null){
	   				var sellerTotal=data.sellerTotal;//商家总价
	   				var workerTotal=data.workerTotal;//工人总价
	   				var startSellerPrice=data.sellerFlagfallPrice;//商家起步价
	   				var startWorkerPrice=data.workerFlagfallPrice;//工人起步价
	   				var workerUnitPrice = data.workerPrice;
	   				var sellerUnitPrice = data.price;
	   				
                $('#'+id).datagrid('updateRow',{
					index: i,
					row: {
						sellerRealPrice:sellerTotal,//商家价 (等级or区域or基础价*数量)
						workerRealPrice:workerTotal,//工人价(区域or基础价*数量)
						sellerStartPrice:startSellerPrice,//商家起步价
						workerStartPrice:startWorkerPrice,//工人起步价
						wokerBasePrice:workerUnitPrice * goodscount,//单价*个数
						sellerBasePrice:sellerUnitPrice * goodscount,//单价*个数
						sellerUnitPrice:sellerUnitPrice,//商家单价
						workerUnitPrice:sellerUnitPrice,//工人单价
					}
				}); 
		    	}
	    	}
	    });
	}
	
	//管理测量订单
	function relationCeliang(){
		var row = selectRow();
		if(row == 0){return false;}
		if(row.status == 11){
			parent.layer.alert("已作废的服务单不能关联测量单!");
			return false;
		}
		if(row.isSettlement == 1){
			parent.layer.alert("已结算的服务单不能关联测量单!");
			return false;
		}
		if(row.isMerge == 1){
			parent.layer.alert("合并单不能关联测量单!");
			return false;
		}
		if(row.serviceType == 3){
			parent.layer.alert("测量订单不能关联测量单!");
			return false;
		}
		//
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: '管理测量订单',
	        content:['buiAdminNeworder/relationCeliang.do?orderId='+row.id,'no'],
	        area: ['1200px', '600px'],
	        
		});
	}
	function isRepeat(value,row,index){
		var isrepeat=row.isrepeat;
		if(isrepeat == 1){
			return "<span style='display: inline-block;float:left;'> "+value+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>重</div>"
		}
		return value;
	}
	
	function Repeat(value,row,index){
		return "<span id='repeat"+row.number+"'>"+value+"</span>";
	}
	
	function toRepeat(data){
		for(var i=0;i<data.rows.length;i++){
        	var row= data.rows[i];
        	reloadRepeat(row.id,row.number,row.firstGoodsType,row.sellerID,row.buyerMobile,row.isrepeat);
        }
	}
	
	//商家近似单和重复单判断
	function sellerReloadRepeat(orderID,number,firstGoodsType,sellerID,buyerMobile,isrepeat){
		var isSameCustomer = 0;
		var ctx = $("#ctx").val();
		$.ajax({
				url : ctx+'/buiNeworder/isSameCustomer.do',//获取商品信息
				type : 'post',
				data : {firstGoodsType:firstGoodsType,sellerID:sellerID,buyerMobile:buyerMobile},
				dataType : "json",
				async: true,
				success : function(data) {
					if(data.num > 0){
						isSameCustomer = data.num;
					}
					if(isrepeat == 1){
						if(parseInt(isSameCustomer) > 1){
							//$("#repeat"+number).html("<span style='display: inline-block;float:left;'> "+"<font color='red'>"+buyerMobile+"</font>"+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>重</div>");
							$("#repeat"+number).html("<span style='display: inline-block;float:left;'> "+"<a style=' display: inline-block;float:left;' href='javascript:showRepeat(\""+orderID+"\",4);'>"+"<font color='red'>"+buyerMobile+"</font>"+"</a> "+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>重</div>");
							return ;
						}
						$("#repeat"+number).html( "<span style='display: inline-block;float:left;'> "+"<a style=' display: inline-block;float:left;' href='javascript:showRepeat(\""+orderID+"\",4);'>"+buyerMobile+"</a> "+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>重</div>");
						return;
					}
					if(parseInt(isSameCustomer) > 1){
					    $("#repeat"+number).html("<font color='red'>"+buyerMobile+"</font>");
						return;
					}
				},
				error : function(result) {//调用失败
				  //alert("网络错误");
				}	
			});
		  }
	
	
	//近似单和重复单判断
	function reloadRepeat(orderID,number,firstGoodsType,sellerID,buyerMobile,isrepeat){
		var isSameCustomer = 0;
		var ctx = $("#ctx").val();
		$.ajax({
				url : ctx+'/buiNeworder/isSameCustomer.do',//获取商品信息
				type : 'post',
				data : {firstGoodsType:firstGoodsType,sellerID:sellerID,buyerMobile:buyerMobile},
				dataType : "json",
				async: true,
				success : function(data) {
					if(data.num > 0){
						isSameCustomer = data.num;
					}
					if(isrepeat == 1){
						if(parseInt(isSameCustomer) > 1){
							$("#repeat"+number).html("<span style='display: inline-block;float:left;'> "+"<a style=' display: inline-block;float:left;' href='javascript:showRepeat(\""+orderID+"\",1);'>"+"<font color='red'>"+buyerMobile+"</font>"+"</a> "+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>重</div>");
							return ;
						}
						$("#repeat"+number).html( "<span style='display: inline-block;float:left;'> "+"<a style=' display: inline-block;float:left;' href='javascript:showRepeat(\""+orderID+"\",2);'>"+buyerMobile+"</a> "+"</span><div style='  display: inline-block;width:25px;border-radius: 5px; text-align:center;font-size:12px; background-color:red;float:left;color:#fff'>重</div>");
						return;
					}
					if(parseInt(isSameCustomer) > 1){
					    $("#repeat"+number).html("<a style=' display: inline-block;float:left;' href='javascript:showRepeat(\""+orderID+"\",3);'>"+"<font color='red'>"+buyerMobile+"</font>"+"</a> ");
						return;
					}
				},
				error : function(result) {//调用失败
				  //alert("网络错误");
				}	
			});
		  }
	
	//查询近似单和重复单
	function showRepeat(orderID,type){
		var title = "查看重复单和近似单";
		if(type == 4){
			title = "查看重复单";
		}
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: title,
	        content:'buiNeworder/toRepeatOrderMsg.do?orderID='+orderID+'&type='+type,
	        area: arrLayerPart	        
		});
	}
	//新增天猫调整单
    function addAdjOrder(){
		var row = selectRow();
		if(row == 0){
			return false;
		}  
		if(row.tmallDirectly != 1){
			parent.layer.alert("只有直营订单才能添加天猫调整单!");
			return false;
		}
    	parent.layer.open({
			type: 2,
			area: [800+'px', 570+'px'],
			fix: false, //不固定
			shade:0.4,
			title:"新增天猫调整单",
			content: "tmalladj/toadd.do?orderId="+row.id,
			success: function(layero, index){
		  }
		});
    }
    
  //加    
   function floatAdd(arg1,arg2){    
        var r1,r2,m;    
        try{r1=arg1.toString().split(".")[1].length;}catch(e){r1=0;}    
        try{r2=arg2.toString().split(".")[1].length;}catch(e){r2=0;}    
        m=Math.pow(10,Math.max(r1,r2));    
        return (arg1*m+arg2*m)/m;    
   }    
         
   //减    
   function floatSub(arg1,arg2){    
       var r1,r2,m,n;    
       try{r1=arg1.toString().split(".")[1].length;}catch(e){r1=0;}    
       try{r2=arg2.toString().split(".")[1].length;}catch(e){r2=0;}    
       m=Math.pow(10,Math.max(r1,r2));    
       //动态控制精度长度    
       n=(r1>=r2)?r1:r2;    
       return ((arg1*m-arg2*m)/m).toFixed(n);    
   }    
          
   //乘    
   function floatMul(arg1,arg2)   {     
       var m=0,s1=arg1.toString(),s2=arg2.toString();     
       try{m+=s1.split(".")[1].length;}catch(e){}     
       try{m+=s2.split(".")[1].length;}catch(e){}     
       return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);     
   }     
         
         
   //除   
   function floatDiv(arg1,arg2){     
         var t1=0,t2=0,r1,r2;     
         try{t1=arg1.toString().split(".")[1].length;}catch(e){}     
         try{t2=arg2.toString().split(".")[1].length;}catch(e){}     
           
         r1=Number(arg1.toString().replace(".",""));  
      
         r2=Number(arg2.toString().replace(".",""));     
         return (r1/r2)*Math.pow(10,t2-t1);     
   }
   
   function amount2Fixed(value,row,index){
	   if(value == undefined){
		   return 0.00;
	   }
	   return (Number(value)).toFixed(2);
   }
   
   function showTmallAdjInfo(number){
		parent.layer.open({
	        type: 2,
	        shade: 0.4,
	        title: '天猫调整单信息',
	        content:['tmalladj/adjinfo.do?number='+number,'no'],
	        area: ['900px', '600px'],
	        
		});
	}
   
   //获取百分比
   function GetPercent(num, total) { 
		num = parseFloat(num); 
		total = parseFloat(total); 
		if (isNaN(num) || isNaN(total)) { 
			return "-"; 
		} 
		return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.00 + "%"); 
	} 
   //停单跳转
   function toStopOrder(ctx){
	   var row = selectRow();
		if(row == 0){
			return false;
		}
		if(row.status == 7 || row.status == 8){
			parent.layer.alert("未完成和已验收的订单不能进行暂停操作！",{icon:7});
			return ;
		}
		if(row.flag == 1 || row.flag == 2){
			parent.layer.alert("平台旗帜为刷单或取消，不能进行暂停操作！",{icon:7});
			return ;
		}
		var id = row.id;
		$.ajax({  
	         type:'POST',      
		     url:ctx+'/buiFuliaoOrder/queryFLWLStatus.do',  
		     data:{'orderId':id},  
		     cache:false,  
		     dataType:'json',  
		     success:function(data){  
		    	 if(data.result){
				    	parent.layer.alert("该订单辅料已发货，不能进行暂停操作！");
				    	return;
					}else{
						parent.layer.open({
					        type: 2,
					        shade: 0.4,
					        title: '暂停',
					        content:ctx+"/buiAdminNeworder/toStopOrder.do?id="+id,
					        area: [800+'px', 450+'px']
					        
						});
					}
		     }  
			});
		
   }
   
   
    var winH = window.screen.height;
	var arrLayerPart2 = new Array();
	if(winH <=900){
		arrLayerPart2 =['1000px', '500px'];
	}else{
		arrLayerPart2 =['1200px', '750px'];
	}
 
	//增加变更
	function addChanges(){
		var row = selectRow();
    	if(row == 0){
    		return false;
    	}
    	if(row.goodsCommentStatus == 1){
    		parent.layer.alert("订单已好评,不允许增加调整!");
    		return false;
    	}
    	if(row.isSettlement == 1){
    		parent.layer.alert("订单已结算,不允许增加调整!");
    		return false;
    	}
    	if (row.status == -4 || row.status==-3 || row.status==-2 || row.status==-1 || row.status==0 
    			|| row.status==9 || row.status==10 || row.status==11 || row.status==12) {
    		parent.layer.alert("审核通过后的服务单，才能新增调整!");
    		return false;
    	}
	 parent.layer.open({
       type: 2,
       shade: 0.4,
       title: '增加调整',
       content:'buiAdminNeworder/toAddChanges.do?orderId='+row.id,
       area: arrLayerPart2,
	  });
	}
	
	function addChangesRefresh(id){
		parent.layer.open({
		       type: 2,
		       shade: 0.4,
		       title: '增加调整',
		       content:'buiAdminNeworder/toAddChanges.do?orderId='+id,
		       area: arrLayerPart2,
			  });
	}
	
	function innerZjAmountFun(value,row,index){
		var level = row.level;
		var sellerZjAmount = row.sellerZjAmount;
		return zjAmountReturn(level,sellerZjAmount,3);
	}
	function outerZjAmountFun(value,row,index){
		var level = row.level;
		var sellerZjAmount = row.sellerZjAmount;
		return zjAmountReturn(level,sellerZjAmount,4);
	}
	
	function zjAmountReturn(level,sellerZjAmount,value){
		var rst = 0;
		if(level != undefined && level != null && level != "" && sellerZjAmount != undefined && sellerZjAmount != null && sellerZjAmount != ""){
			if(level == value){
				rst = sellerZjAmount;
			}
		}
		return amount2Fixed(rst);
	}
	
	//支付方式
	function orderPayModeValue(value,row,index){
		if(value == 1){
			return "后付";
		}else if(value == 2){
			var sellerAlsoPay = Number(row.sellerAlsoPay);
			if(sellerAlsoPay　!='undifined' && sellerAlsoPay > 0) {
				return "<div style='color:red;'>预付"+sellerAlsoPay.toFixed(2)+"</div>";
			}
			return "预付";
		}else{
			return "";
		}
	}
	
	//JQuery中的id选择器含有特殊字符时，不能选中dom元素的解决方法
	function escapeJquery(srcString)  
    {  
        // 转义之后的结果  
        var escapseResult = srcString;  
        // javascript正则表达式中的特殊字符  
        var jsSpecialChars = ["\\", "^", "$", "*", "?", ".", "+", "(", ")", "[",  
                "]", "|", "{", "}"];  
        // jquery中的特殊字符,不是正则表达式中的特殊字符  
        var jquerySpecialChars = ["~", "`", "@", "#", "%", "&", "=", "'", "\"",  
                ":", ";", "<", ">", ",", "/"];  
        for (var i = 0; i < jsSpecialChars.length; i++) {  
            escapseResult = escapseResult.replace(new RegExp("\\"  
                                    + jsSpecialChars[i], "g"), "\\"  
                            + jsSpecialChars[i]);  
        }  
        for (var i = 0; i < jquerySpecialChars.length; i++) {  
            escapseResult = escapseResult.replace(new RegExp(jquerySpecialChars[i],  
                            "g"), "\\" + jquerySpecialChars[i]);  
        }  
        return escapseResult;  
    } 
	
	
